package Servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import anonymus.excepcion.DAOExcepcion;
import anonymus.modelo.Cancha;
import anonymus.negocio.CanchaNegocio;

/**
 * Servlet implementation class BuscarCanchaServlet
 */
@WebServlet("/BuscarCanchaServlet")
public class BuscarCanchaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarCanchaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                                               
}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		
		int distrito = Integer.parseInt(request.getParameter("cboDistrito"));
		System.out.println(distrito + "distrito");
		String dis ="";
				if(distrito==0){
					dis="La Molina";
				}
				else if(distrito==1){
					dis="Miraflores";
				}
				else if(distrito==2){
					dis="Surco";
				}
				
		 
				
				
		String fecha = request.getParameter("txtDia");
			
		String HoraInicio = request.getParameter("cboHoraInicio");

		String MinutosInicio = request.getParameter("cboMinutosInicio");

		String HoraFin = request.getParameter("cboHoraFin");

		String MinutosFin = request.getParameter("cboMinutosFin");

		String Inicio = (HoraInicio + ":" + MinutosInicio);
		String Fin = (HoraFin + ":" + MinutosFin);
		
		System.out.println(dis + fecha + Inicio + Fin);
		
		if(fecha!=null ){
		
		CanchaNegocio neg = new CanchaNegocio();
		Collection<Cancha> adm=new ArrayList<Cancha>();
             try {
            	 		adm = neg.buscarCanchas(dis, fecha, Inicio, Fin);
            	 		
            	 		System.out.print(adm.size());
        				
        				request.setAttribute("Canchitas", adm);
        				RequestDispatcher rd = request.getRequestDispatcher("BuscarCancha.jsp");
        				rd.forward(request, response);	
                        }
                catch (DAOExcepcion e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
              
	}

	else{
	System.out.println("Falta llenar Fecha");
	}
	}
}

